package com.supermate.init.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Optional;

/**
 * @Author: 冰岩
 * @Date: 2023/10/29
 * @Description:
 */
public class DateUtil {

    public static final String YMDHMS = "yyyy-MM-dd HH:mm:ss";
    public static final String YMD_HMS= "yyyyMMdd_HHmmss";
    public static Optional<String> date2StrYMDHMS(Date date) {
        return formatDate(date, YMDHMS);
    }

    public static Optional<String> formatDate(Date date, String pattern) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            return Optional.of(sdf.format(date));
        } catch (Throwable t) {
            return Optional.empty();
        }
    }

}
